<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>订单号：</label>
                                <input type="text" name="orderNum"/>
                            </li>
                            <li>
                                <label>用户ID：</label>
                                <input type="text" name="userId"/>
                            </li>
                            <li>
                                <label>下单日期：</label>
                                <input type="text" class="time-input" placeholder="请选择下单日期" name="genDate"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="admin:order:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="admin:order:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('admin:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('admin:order:remove')}]];
        var prefix = ctx + "admin/order";

        $(function() {
            var options = {
                url: prefix + "/listAll",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "订单",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'orderId',
                    title: '订单唯一标识',
                    visible: false
                },
                {
                    field: 'orderNum',
                    title: '订单号'
                },
                {
                    field: 'userId',
                    title: '用户ID'
                },
                {
                    field: 'genDate',
                    title: '下单日期'
                },
                    {
                        field: 'price',
                        title: '总价',
                        formatter: function (value, row, index) {
                            return "￥ "+row.price;
                        },
                    },
                    {
                        field: 'payStatus',
                        title: '支付状态',
                        formatter: function (value, row, index) {
                            if (row.payStatus == 0) {
                                return '<strong style="color: red">未支付</strong>';
                            } else if (row.payStatus == 1) {
                                return '<strong style="color: #00B83F">已支付</strong>';
                            }
                        },
                    },
                    {
                        field: 'status',
                        title: '订单状态',
                        formatter: function (value, row, index) {
                            if (row.status == 0) {
                                return '<strong style="color: #00B83F">正常</strong>';
                            } else if (row.status == 2) {
                                return '<strong style="color: #5e5e5e">关闭</strong>';
                            }
                        },
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status == 0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="closeOrder(\'' + row.orderId + '\')"><i class="fa fa-edit"></i>关闭</a> ');
                        }
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.orderId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="openInfo(\'' + row.orderId + '\')"><i class="fa fa-crosshairs"></i>详情</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /* 打开订单信息 */
        function openInfo(orderId) {
            var url = prefix + '/orderWithDetailAdmin/' + orderId;
            $.modal.openTab("订单信息", url);
        }

        //关闭订单
        function closeOrder(orderId) {
            $.modal.confirm("确认要关闭订单吗？", function() {
                $.operate.post(ctx + "admin/order/closeOrder", {orderId});
            })
        }
    </script>
</body>
</html>